//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Microsoft.TridentWordAddIn.Presentation
{
    /// <summary>
    /// class TransparentRichTextBox
    /// </summary>
    public partial class TransparentRichTextBox : RichTextBox
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TransparentRichTextBox"/> class.
        /// </summary>
        public TransparentRichTextBox()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// </summary>
        /// <value></value>
        /// <returns>A <see cref="T:System.Windows.Forms.CreateParams"/> representing the information needed when creating a control.</returns>
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams prams = base.CreateParams;
                if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
                {
                    prams.ExStyle |= 0x020; // transparent
                    prams.ClassName = "RICHEDIT50W";
                }

                return prams;
            }
        }

        /// <summary>
        /// Loads the library.
        /// </summary>
        /// <param name="libraryName">Name of the library.</param>
        /// <returns>IntPtr</returns>
        [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        private static extern IntPtr LoadLibrary(string libraryName);
    }
}
